package com.c.ctgproject.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import cn.jzvd.JzvdStd
import com.bumptech.glide.Glide
import com.c.ctgproject.R
import com.c.ctgproject.base.BaseEmptyRecyclerViewAdapter
import com.c.ctgproject.base.BaseEmptyRecyclerViewAdapterV2
import com.github.chrisbanes.photoview.PhotoView

class PhotoVideoListAdapter(private val context: Context, private val urls:ArrayList<String>) : BaseEmptyRecyclerViewAdapterV2(context, urls) {
    override fun createViewHolder(parent: ViewGroup): RecyclerView.ViewHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.item_photo_video_list, parent, false)
        return MyViewHolder(view)
    }

    override fun handlerData(holder: RecyclerView.ViewHolder, position: Int) {
        if (holder is MyViewHolder) {
            val url=urls[position]
            val isVideo=false
            if (isVideo) {
                //holder.mTitleTv.text = "视频"
                holder.mPhotoImageIV.visibility = View.GONE
                holder.mVideoRV.visibility = View.VISIBLE
                holder.mVideoView.setUp(url, "")
                Glide.with(context).load(url).into( holder.mVideoView.posterImageView)

            } else {
                //holder.mTitleTv.text = "图片"
                holder.mPhotoImageIV.visibility = View.VISIBLE
                holder.mVideoRV.visibility = View.GONE
                Glide.with(context).load(url).into(holder.mPhotoImageIV)
            }
        }
    }

    inner class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        //        val mTitleTv: TextView=view.findViewById(R.id.mTitleTv)
        val mPhotoImageIV: PhotoView =view.findViewById(R.id.mPhotoImageIV)
        val mVideoRV: RelativeLayout =view.findViewById(R.id.mVideoRV)
        val mVideoView: JzvdStd =view.findViewById(R.id.mVideoView)
    }
}